/*
 * Copyright (c) 2022-2025 KCloud-Platform-IoT Author or Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package org.laokou.common.core.config;

import lombok.extern.slf4j.Slf4j;
import org.laokou.common.core.util.RequestUtils;
import org.springframework.context.annotation.Bean;

/**
 * 预热.
 *
 * @author laokou
 */
@Slf4j
public class WarmUpConfig {

	@Bean(initMethod = "init", bootstrap = Bean.Bootstrap.BACKGROUND)
	public WarmUp warmUp() {
		log.info("{} => Initializing WarmUpConfig", Thread.currentThread().getName());
		return new WarmUp();
	}

	public static class WarmUp {

		private static final String DEFAULT_USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3";

		public void init() {
			log.info("加载Browscap预热...");
			// 预热
			RequestUtils.getUserAgentParser().parse(DEFAULT_USER_AGENT);
			log.info("完成Browscap预热...");
		}

	}

}
